package org.zhengquan.util;

import java.util.Random;

/**
 * @author zhengquan
 * @date 2017/10/31
 */
public class PasswordUtil {

    public static String randomPassword() {
        StringBuffer stringBuffer = new StringBuffer();
        Random random = new Random(System.currentTimeMillis());
        int length = random.nextInt(3) + 8;
        for (int i = 0; i < length; i++) {
            boolean b = random.nextBoolean();
            if (b) {
                // 字符串
                //取得65大写字母还是97小写字母
                int choice = random.nextBoolean() ? 65 : 97;
                // 取得大写字母
                stringBuffer.append((char) (choice + random.nextInt(26)));
            } else {
                // 数字
                stringBuffer.append(String.valueOf(random.nextInt(10)));
            }

        }
        return stringBuffer.toString();
    }

    public static void main(String[] args) throws Exception{
        String password = "123456";
        String encodePassword = MD5Util.MD5EncodeUtf8(password);
        System.out.println(password);
        System.out.println(encodePassword);

    }
}
